<?php
require(dirname(dirname(__FILE__))."/Config/config.php");
require(dirname(dirname(__FILE__))."/jssdk.php");
class readController extends  appController{
	public $wxid = 0;//数据库Id
	
	public $m;//自己的model
	public $info=array();//当前用户的微信信息
	
	
	public function record()
	{
	
		$this->check_member();
		
		$info = Model('read')->getRecord($_SESSION['wxid']);
	
		$this->assign('info',$info);
	
		$config[c] = array('site_name' => "阅城之味");
	
		$this->assign_global($config);
	
		$jsdk = Model('read')->get_jsdk();
	
		$this->assign("jsdk", $jsdk);
	
		$this->display("perfume.html");
	}
	
	
	public function index(){
		$this->check_member();
		$info = Model('read')->getRecord($_SESSION['wxid']);
		$config[c] = array('site_name' => "阅城之味");
		$this->assign_global($config);
		$jsdk = Model('read')->get_jsdk();
		$this->assign("jsdk", $jsdk);
		//获取点赞数量和自己本身点赞的信息
		$votes = Model('read')->get_read_vote($_SESSION['wxid']);
		$this->assign("vote", $votes);
		$this->display("index.html");
	}
	public function set()
	{
		$_SESSION['wxid']=$_GET['wxid'];
	}
	//清除数据
	public function clear()
	{
	
		unset($_SESSION['wxid']);
		unset($_SESSION['pid']);
		echo "已清除数据";
		exit;
	}
	//需要授权才可进入游戏
	public function canIn()
	{
		if(!$_SESSION['wxid'])
		{
			header("Location:http://".$_SERVER['HTTP_HOST']."/ws/index.php?g=mobile&m=read&a=index");
			exit;
		}
	}
	
	public function save_vote(){
		if(!$_SESSION['wxid'])
		{
			$result=array("error"=>1,"content"=>"请点击后刷新重新投票");
			$this->showMsg($result);
		}
		$info['vote'] = isset($_POST['vote'])?intval($_POST['vote']):1;
		$info['wxid']= $_SESSION['wxid'];
		Model('read')->insert($info,"read_vote");
		$result=array("error"=>0,"content"=>"投票成功");
		$this->showMsg($result);
	}
	
	
	public function bookcoupons(){
		$config[c] = array('site_name' => "阅城之味");
		$this->assign_global($config);
		$jsdk = Model('read')->get_jsdk();
		$this->assign("jsdk", $jsdk);
		$this->display("bookcoupons.html");
	}
	
	public function perfume(){
		$config[c] = array('site_name' => "阅城之味");
		$this->assign_global($config);
		$jsdk = Model('read')->get_jsdk();
		$this->assign("jsdk", $jsdk);
		$this->display("perfume.html");
	}
	
	
	public function ajaxCard()
	{
		$cardList[0]['cardId'] = Model('read')->get_cfg("card_number");
		$jsdk_card = Model('read')->build_jsdk_card($cardList);
		
		echo json_encode($jsdk_card);
	
	}
}